package com.ph.irp.base.assistantmaterial.service.impl;

import java.util.List;

import com.ph.irp.base.assistantmaterial.dao.PBaseAssistantmaterialAreaDAO;
import com.ph.irp.base.assistantmaterial.service.PBaseAssistantmaterialAreaService;
import com.ph.irp.model.PBaseAssistantmaterialArea;

public class PBaseAssistantmaterialAreaServiceImpl implements
		PBaseAssistantmaterialAreaService {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5872995622477407241L;
	private PBaseAssistantmaterialAreaDAO areaDAOProxy;
	
	public PBaseAssistantmaterialAreaDAO getAreaDAOProxy() {
		return areaDAOProxy;
	}

	public void setAreaDAOProxy(PBaseAssistantmaterialAreaDAO areaDAOProxy) {
		this.areaDAOProxy = areaDAOProxy;
	}


	@Override
	public void addArea(PBaseAssistantmaterialArea area) throws Throwable {

		areaDAOProxy.addAssistantmaterialArea(area);

	}

	@Override
	public void deleteArea(String[] areaIds) throws Throwable {

		for (String areaId : areaIds)
			areaDAOProxy.deleteAssistantmaterialArea(areaId);

	}

	@Override
	public List<PBaseAssistantmaterialArea> getAreas(
			PBaseAssistantmaterialArea area) throws Throwable {
		List<PBaseAssistantmaterialArea> areas = null;

		if (area == null) {
			areas = areaDAOProxy.getAllAssistantmaterialAreas();
		} else if (area.getAreaCode() != null
				&& !area.getAreaCode().trim().equals("")
				&& area.getAreaName() != null
				&& !area.getAreaName().trim().equals("")) {
			areas = areaDAOProxy.getAssistantmaterialAreasByCodeAndName(area.getAreaCode(), area
					.getAreaName());
		} else if (area.getAreaCode() != null
				&& !area.getAreaCode().trim().equals("")) {
			areas = areaDAOProxy.getAssistantmaterialAreasByCode(area.getAreaCode());
		} else if (area.getAreaName() != null
				&& !area.getAreaName().trim().equals("")) {
			areas = areaDAOProxy.getAssistantmaterialAreasByName(area.getAreaName());
		} else {
			areas = areaDAOProxy.getAllAssistantmaterialAreas();
		}

		return areas;
	}
	
	@Override
	public List<PBaseAssistantmaterialArea> getAllAreas() throws Throwable {
		return areaDAOProxy.getAllAssistantmaterialAreas();
	}

	@Override
	public List<PBaseAssistantmaterialArea> getAreasByCodeAndName(String areaCode, String areaName)
			throws Throwable {
		return areaDAOProxy.getAssistantmaterialAreasByCodeAndName(areaCode, areaName);
	}

	@Override
	public List<PBaseAssistantmaterialArea> getAreasByCode(String areaCode)
			throws Throwable {
		return areaDAOProxy.getAssistantmaterialAreasByCode(areaCode);
	}

	@Override
	public List<PBaseAssistantmaterialArea> getAreasByName(String areaName)
			throws Throwable {
		return areaDAOProxy.getAssistantmaterialAreasByName(areaName);
	}

	@Override
	public PBaseAssistantmaterialArea getAreasById(int areaId) throws Throwable {

		return areaDAOProxy.getAssistantmaterialAreaById(areaId);

	}

	@Override
	public void updateArea(PBaseAssistantmaterialArea area) throws Throwable {

		areaDAOProxy.updateAssistantmaterialArea(area);

	}

}
